<template>
  <div class="app-container">
    <el-form
      ref="elForm"
      :disabled="$route.query.isInfo"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="120px"
    >
      <h2 style="text-align: center">试验室人员考核评价记录内容设置</h2>
      <h4 class="form-header h4">基本信息</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="方式" prop="type">
            <el-select
              v-model="formData.type"
              filterable
              placeholder="请选择方式"
            >
              <el-option
                v-for="dict in dict.type.sys_check_content_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="排序" prop="sort">
            <el-input-number
              v-model="formData.sort"
              controls-position="right"
              :min="0"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="内容" prop="content">
            <el-input
              :autosize="{ minRows: 4, maxRows: 6 }"
              v-model="formData.content"
              type="textarea"
              placeholder="请输入内容"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-col :span="24">
        <el-form-item
          label-width="0"
          style="text-align: center; margin-top: 30px"
        >
          <el-button
            v-if="!$route.query.isInfo"
            type="primary"
            @click="submitForm"
            >提交</el-button
          >
          <el-button :disabled="false" @click="resetForm">返回</el-button>
        </el-form-item>
      </el-col>
    </el-form>
  </div>
</template>

<script>
import {
  checkappraiseContentSettingAdd,
  updategcheckappraiseContentSetting,
  checkappraiseContentSettingInfo,
} from "@/api/cultivate/content.js";
export default {
  components: {},
  dicts: ["sys_check_content_type"],
  props: [],
  data() {
    return {
      formData: {
        type: undefined,
        sort: undefined,
        content: undefined,
      },
      rules: {
        sort: [
          {
            required: true,
            message: "请输入排序",
            trigger: ["blur"],
          },
        ],
        type: [
          {
            required: true,
            message: "请选择类型",
            trigger: "change",
          },
        ],
        content: [
          {
            required: true,
            message: "请输入内容",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  created() {
    if (this.$route.query.isEdit || this.$route.query.isInfo) {
      this.getinfo();
    }
  },
  mounted() {},
  methods: {
    getinfo() {
      checkappraiseContentSettingInfo(this.$route.query.id).then((response) => {
        this.formData = response.data;
      });
    },
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          let query = JSON.parse(JSON.stringify(this.formData));
          if (this.formData.checkAppraiseRecordContentSettingId != undefined) {
            updategcheckappraiseContentSetting(query).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.resetForm();
            });
          } else {
            checkappraiseContentSettingAdd(query).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.resetForm();
            });
          }
        }
      });
    },
    resetForm() {
      const obj = { path: "./content" };
      this.$tab.closeOpenPage(obj);
    },
  },
};
</script>
